package com.example.util;


import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
 * Created with IntelliJ IDEA.
 * User: tao95
 * Date: 2017/5/8
 * Time: 16:12
 * To change this template use File | Settings | File Templates.
 * Description:
 */
public class MatcherUtil {
    /**
     * 邮箱名格式匹配器
     *
     * @param mail      要验证格式的邮箱名
     * @return boolean      是否匹配
     */
    public static boolean mailMatcher(String mail){
        String check = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
        Pattern regex = Pattern.compile(check);
        Matcher matcher = regex.matcher(mail);
        boolean isMatched = matcher.matches();
        return isMatched;
    }

    /**
     * 邮箱名格式匹配器
     *
     * @param phone      要验证格式的手机号
     * @return boolean      是否匹配
     */
    public static boolean phoneMatcher(String phone){
        String check = "^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
        Pattern regex = Pattern.compile(check);
        Matcher matcher = regex.matcher(phone);
        boolean isMatched = matcher.matches();
        return isMatched;
    }
}